const {
  http
} = require("../../../../utils/apiutils");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    jobData: "",
    userInfo: "",
    show: false,
    minHour: 10,
    maxHour: 20,
    minDate: new Date().getTime(),
    maxDate: new Date().getTime(),
    currentDate: new Date().getTime(),
    title:"请选择面试时间"

  },
  add0(m){ return m < 10 ? '0' + m : m },

  onInput(event) {
    
    var time = new Date(event.detail);
    var year = time.getFullYear();
    var month = time.getMonth()+1;
    var date = time.getDate();
    var hours = time.getHours();
    var minutes = time.getMinutes();
    var seconds = time.getSeconds();
    this.setData({
      currentDate: event.detail,
      interviewDate: year+'-'+this.add0(month)+'-'+this.add0(date)+' '+this.add0(hours)+':'+this.add0(minutes)+':'+this.add0(seconds),
      title:  year+'-'+this.add0(month)+'-'+this.add0(date)+' '+this.add0(hours)+':'+this.add0(minutes)
    });
    console.log("-----选择的时间---",this.data.currentDate);
  },
  baoming1: function () {


    let arr = getCurrentPages()

    var  page = arr[arr.length-2];
    page.setData({
      checked:true,
    })
    wx.navigateBack({
      delta: 1,
    })
    return

    if (this.data.jobData.type == 2) {
      this.setData({
        show: true,
      })
    } else {
      thia.baoming();
    }
  },


  baoming: function () {

    var that = this;
    wx.showLoading({
      title: '加载中...',
    })
     var data = {
      lng: this.data.longitude, //经度信息
      lat: this.data.latitude, //维度信息
      // interviewDate: "2021-01-27 09:00:00",
      inviteCode: "" // 推荐码   (没有推荐人时可为空)
    };
    if(this.data.jobData.type==2)
    {
      data["interviewDate"] = this.data.interviewDate
    }
    http.registration(this.data.jobData.id, data,
      function (res) {
        wx.hideLoading()
        if (res.code == 0) {
          wx.switchTab({
            url: '/pages/tabBar/home/index',
            success: (res) => {
              wx.showToast({
                title: "报名成功",
                icon: "none",
              })
            },
            fail: (res) => {},
            complete: (res) => {},
          })
        } else {
          wx.showToast({
            title: res.message,
            icon: "none",
          })
        }
      },
      function (err) {
        wx.hideLoading()
      })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let job = getApp().globalData.workInfo
    this.setData({
      jobData: job,
      userInfo: getApp().globalData.userInfo,
    })





    console.log("----------", this.data.jobData);
    var that = this;
    wx.getLocation({
      type: 'gcj02',
      success: function (res) {
        console.log(res);
        that.data.latitude = res.latitude;
        that.data.longitude = res.longitude;
      },
    })

    if (job.type == 2) {
      
      if(job.asOfTime)
      {
        var date = job.asOfTime.replace(/-/g,'/'); //必须把日期'-'转为'/'
        var timestamp = new Date(date).getTime();
        this.setData({
          maxDate:timestamp,
        })
      }
    }
  },

  confirm:function(){

      this.baoming();
  },
  onClose: function () {
    this.setData({
      show: false,
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    var shareObj = {
      title: "分享岗位", // 默认是小程序的名称(可以写slogan等)
      path: getApp().globalData.userInfo.inviteCode?'/pages/index/index?code='+getApp().globalData.userInfo.inviteCode:'/pages/index/index', // 
      imageUrl: '',
      success: function (res) {
        // 转发成功之后的回调
        if (res.errMsg == 'shareAppMessage:ok') {
        }
      }
    }
    console.log("------------", shareObj);
    // 返回shareObj
    return shareObj;
  }
})